package com.study.reflect.aop;

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @Author HBZ
 * @Date 2020/7/30 10:00
 * @Description
 */
public class MyInvocationHandler implements InvocationHandler {
    private Object target;

    public void setTarget(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object result;
        Class clazz=MyAspect.class;
        Method method1=clazz.getMethod("before",null);
        MyBefore annotation=method1.getAnnotation(MyBefore.class);
        if(annotation!=null){
            MyAspect aspect=new MyAspect();
            aspect.before();
        }
        result=method.invoke(target,args);
        return result;
    }
}
